<template>
	<view class="content">
		<!-- #ifdef MP-WEIXIN -->
		<button class="cell-btn">微信登录</button>
		<button class="cell-btn">微信获取手机登录</button>
		<!-- #endif -->
		<!-- #ifdef MP-ALIPAY -->
		<button class="cell-btn" @click="onPayLogin">支付宝登录</button>
		<button class="cell-btn" open-type="getPhoneNumber" @getphonenumber="onGetphonenumber">支付宝手机登录</button>
		<!-- #endif -->
		<button class="cell-btn">账号密码登录</button>
	</view>
</template>

<script setup>
const weiUserCo = uniCloud.importObject('wei-user-co');

const onPayLogin = async () => {
	const { code } = await uni.login({
		scopes: ["auth_base"],
	})
	const res = await weiUserCo.loginByAlipay({
		code
	})
}
const onGetphonenumber = async (res) => {
	const { encryptedData } = res.detail;
	uni.getPhoneNumber({
		success: (res) => {
			const { response } = JSON.parse(res.response);
			weiUserCo.loginByAlipayMobile({ encryptedData: response });
		}
	})
}
</script>

<style>
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
.cell-btn {
	width: 500rpx;
	margin-top: 20px;
}
</style>
